package com.riku.security.common;

/**
 * 统一返回
 */
public class SeCommonResponse<T> {
    private boolean success;
    private String message;
    private T data;

    public static SeCommonResponse success(){
        SeCommonResponse response = new SeCommonResponse();
        response.setSuccess(true);
        return response;
    }

    public static <T> SeCommonResponse success(T t){
        SeCommonResponse response = new SeCommonResponse();
        response.setSuccess(true);
        response.setData(t);
        return response;
    }

    public static SeCommonResponse fail(String msg){
        SeCommonResponse response = new SeCommonResponse();
        response.setSuccess(false);
        response.setMessage(msg);
        return response;
    }

    public static SeCommonResponse fail(){
        SeCommonResponse response = new SeCommonResponse();
        response.setSuccess(false);
        return response;
    }

    public static <T> SeCommonResponse fromException(SeSecurityException e){
        SeCommonResponse response = new SeCommonResponse();
        response.setSuccess(false);
        response.setMessage(e.getMessage());
        return response;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
